<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/6/17
  Time: 10:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>员工列表</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/employee.css" type="text/css"/>
<script src="${pageContext.request.contextPath}/scripts/jquery-3.0.0.js"></script>
<body>
<%
    pageContext.setAttribute("ctp", request.getContextPath());
%>
<h3>员工列表</h3>
${info.list}
    <table border="1" cellpadding="5" cellspacing="0">
        <caption>员工基本信息列表</caption>
        <tr>
            <th>员工编号</th>
            <th>lastName</th>
            <th>员工性别</th>
            <th>员工邮箱</th>
            <th>部门编号</th>
            <th>操作</th>
        </tr>
        <c:forEach var="emp" items="${pageInfo.list}">
            <tr>
                <td>${emp.tid}</td>
                <td>${emp.lastName}</td>
                <td>${emp.gender==1?"女":"男" }</td>
                <td>${emp.email}</td>
                <td>${emp.dId}</td>
                <td><a href="${ctp}/emp/${emp.tid}">edit</a>&nbsp;|&nbsp;
                <a href="${ctp}/emp/${emp.tid}" class="delBtn">delete</a></td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="6">
                <a href="${ctp}/emps?id=0">首页</a><a href="${ctp}/emps?id=${pageInfo.prePage}">上一页</a>

                <c:forEach items="${pageInfo.navigatepageNums}" var="num">
                    <c:if test="${num == pageInfo.pageNum}">
                        【${num}】
                    </c:if>
                    <c:if test="${num != pageInfo.pageNum}">
                        <a href="${ctp}/emps?id=${num}">${num}</a>
                    </c:if>
                </c:forEach>

                <a href="${ctp}/emps?id=${pageInfo.nextPage}">下一页</a><a href="${ctp}/emps?id=${pageInfo.pages}">末页</a>
            </td>
        </tr>
        <tr>
            <td colspan="6">
                <a href="${ctp}/addEmployee">点击添加新员工</a>
            </td>
        </tr>
    </table>
    <form id="deleteForm" action="${ctp}/emp/${emp.tid}" method="post">
        <input type="hidden" name="_method" value="DELETE" />
    </form>
    <h3>
        ${ctp}
    </h3>
    <script>
        $(function(){
            $(".delBtn").click(function(){
                //0、确认删除？
                //1、改变表单的action指向；
                $("#deleteForm").attr("action",this.href);
                //2、提交表单；
                $("#deleteForm").submit();
                return false;
            });
        });
    </script>

</body>
</html>
